# -*- coding: utf-8 -*- 
#!/usr/bin/python2.7
"""MVC的cotroler,url映射后会生成对象，并且调用GET或者POST返回"""

__authors__ = [
  '"BigYuki" <sheyuqi@gmail.com>',
] 
from core.services.FormService import FormServiceFactory
from core.services.DataService import DataServiceFactory
from core.services.OauthService import FlickrOauthService
from core.pages import BlogPage

class PageFactory(object):
    @staticmethod
    def MainPageInstance(*args,**kw):
        return MainPage(*args,**kw)
    @staticmethod
    def LoginPageInstance(*args,**kw):
        return LoginPage(*args,**kw)
    @staticmethod
    def BlogUpdatePageInstance(*args,**kw):
        return BlogUpdatePage(*args,**kw)
    @staticmethod
    def NavigationListPageInstance(*args,**kw):
        return NavigationListPage(*args,**kw)
    @staticmethod
    def NavigationNewPageInstance(*args,**kw):
        return NavigationNewPage(*args,**kw)
    @staticmethod
    def NavigationEditPageInstance(*args,**kw):
        return NavigationEditPage(*args,**kw)
    @staticmethod
    def AdminEditPageInstance(*args,**kw):
        return AdminEditPage(*args,**kw)
    @staticmethod
    def CategoryListPageInstance(*args,**kw):
        return CategoryListPage(*args,**kw)
    @staticmethod
    def CategoryNewPageInstance(*args,**kw):
        return CategoryNewPage(*args,**kw)
    @staticmethod
    def CategoryEditPageInstance(*args,**kw):
        return CategoryEditPage(*args,**kw)
    @staticmethod
    def ArticleListPageInstance(*args,**kw):
        return ArticleListPage(*args,**kw)
    @staticmethod
    def ArticleNewPageInstance(*args,**kw):
        return ArticleNewPage(*args,**kw)
    @staticmethod
    def ArticleEditPageInstance(*args,**kw):
        return ArticleEditPage(*args,**kw)
    @staticmethod
    def ImageOauthLinkPageInstance(*args,**kw):
        return ImageOauthLinkPage(*args,**kw)
    @staticmethod
    def ImageUploadPageInstance(*args,**kw):
        return ImageUploadPage(*args,**kw)
    @staticmethod
    def ImageOAuthorizeSuccessPageInstance(*args,**kw):
        return ImageOAuthorizeSuccessPage(*args,**kw)
    @staticmethod
    def ImageListPageInstance(*args,**kw):
        return ImageListPage(*args,**kw)
class BasicPage(BlogPage):
    """BasicPage获取基本页面数据。"""
    def __init__(self):
        BlogPage.__init__(self)
        self.blog=DataServiceFactory.BlogServiceInstance().get()
    def getTemplateAbsPath(self):
        themeAbsDiretory='admin/themes'
        themeFolder='default'
        return themeAbsDiretory+'/'+themeFolder+'/'+self.templateFile

class MainPage(BasicPage):
    """首页"""
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='main.html'
        
class LoginPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='login.html'
        self.form=FormServiceFactory.LoginFormServiceInstance().get()
        
class BlogUpdatePage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='blogUpdate.html'
        self.form=FormServiceFactory.BlogUpdateFormServiceInstance().get()


class NavigationListPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='navigationList.html'
        self.navigationList=DataServiceFactory.NavigationServiceInstance().all()

class NavigationNewPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='navigationNew.html'
        self.form=FormServiceFactory.NavigationNewFormServiceInstance().get()

class NavigationEditPage(BasicPage):
    def __init__(self,navigationID):
        BasicPage.__init__(self)
        self.templateFile='navigationEdit.html'
        self.form=FormServiceFactory.NavigationUpdateFormServiceInstance(navigationID).get()
        self.navigationID=navigationID
        
        
class AdminEditPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='adminEdit.html'
        self.form=FormServiceFactory.AdminUpdateFormServiceInstance().get()

class CategoryListPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='categoryList.html'
        self.categoryList=DataServiceFactory.CategroyServiceInstance().all()
        
class CategoryNewPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='categoryNew.html'
        self.form=FormServiceFactory.CategoryNewFormServiceInstance().get()
        
class CategoryEditPage(BasicPage):
    def __init__(self,categoryID):
        BasicPage.__init__(self)
        self.templateFile='categoryEdit.html'
        self.form=FormServiceFactory.CategoryUpdateFormServiceInstance(categoryID).get()
        self.categoryID=categoryID
        
class ArticleListPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='articleList.html'
        self.articleList=DataServiceFactory.ArticleServiceInstance().all()

class ArticleNewPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='articleNew.html'
        self.form=FormServiceFactory.ArticleNewFormServiceInstance().get()
        
class ArticleEditPage(BasicPage):
    def __init__(self,articleID):
        BasicPage.__init__(self)
        self.templateFile='articleEdit.html'
        self.form=FormServiceFactory.ArticleUpdateFormServiceInstance(articleID).get()
        self.articleID=articleID
        
class ImageOauthLinkPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='imageOAuthLink.html'
        self.oauthLink=FlickrOauthService.GetLoginURL()
class ImageUploadPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='imageUpload.html'
        self.form=FormServiceFactory.ImageUploadFormServiceInstance().get()

class ImageOAuthorizeSuccessPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='imageOAuthorizeSuccess.html'
        self.flickrOauth=FlickrOauthService.GetFlickrOauth().userID
        
class ImageListPage(BasicPage):
    def __init__(self):
        BasicPage.__init__(self)
        self.templateFile='imageList.html'
        self.photoList=DataServiceFactory.ImageServiceInstance().all()
#class UploadImgAuthCancle:
#    def GET(self):
#        FlickrOauthService.CancelAuth()
#        web.seeother('/admin/uploadimg',absolute=True)
#        return None
#
#
#class UploadImgPage(BasicPage):
#    """上传图片表单页面"""
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='uploadimg.html'
#        self.message=None
#        self.photoUrl=None
#    @FlickrOauthService.CheckAuthDecorator
#    def GET(self):
#        return self.render()
#    #@FlickrOauthService.CheckAuthDecorator
#    def POST(self):
#        photoInput = web.input(photo={})
#        self.photoUrl=ImageService.Upload(photoInput['photo'])
#        return self.render()
#        #return "上传图片成功"
#
#class AbcPage(BasicPage):
#    """上传图片表单页面"""
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='uploadimg.html'
#    @FlickrOauthService.CheckAuthDecorator
#    def GET(self):
#        return self.render()
#    @FlickrOauthService.CheckAuthDecorator
#    def POST(self):
#        x = web.input(myfile={})
#        return "success"#x['myfile'].value
#
#class UploadImgAuthPage(BasicPage):
#    """图片授权页面"""
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='uploadimg_auth.html'
#    def GET(self):
#        oauthVerifier=web.input().oauth_verifier
#        FlickrOauthService.AuthWithFrob(oauthVerifier)
#        #self.oauthVerifier=oauthVerifier
#        #self.oauth
#        return "页面授权成功，请关闭"
#
#class UploadImgAuthCheckPage(BasicPage):
#    """授权提醒与检测页面"""
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='uploadimg_auth_check.html'
#    def GET(self):
#        self.url=FlickrOauthService.GetLoginURL()
#        return self.render()
#



#class TagPage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='tag.html'
#        self.message=None
#        self.dashboadSelect['tag']=True
#        self.tagList=TagService.GetList()
#    @AdministratorService.CheckLoginDecorator
#    def GET(self):
#        return self.render()
#
#class TagDeletePage(TagPage):
#    def __init__(self):
#        TagPage.__init__(self)
#    @AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        id=int(id)
#        self.form=None
#        if TagService.DeleteById(id):
#            self.message=u"删除成功"
#        else:
#            self.message=u"删除失败"
#        return self.render()
#
#class SingleArticlePage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='singleArticle.html'
#        self.message=None
#        self.dashboadSelect['page']=True
#        self.actionType='view'
#    #@AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.singleArticleList=SingleArticleService.GetList()
#        return self.render()
#
#class SingleArticleAddPage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='singleArticle.html'
#        self.message=None
#        self.dashboadSelect['page']=True
#        self.actionType='add'
#    #@AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.form=SingleArticleService.GetForm()
#        return self.render()
#    #@AdministratorService.CheckLoginDecorator
#    def POST(self):
#        self.form=SingleArticleService.GetForm()
#        if not self.form.validates():
#            self.message=u'输入有误'
#            return self.render()
#        else:
#            if SingleArticleService.PutByForm(self.form):
#                self.message=u'插入成功'
#            else:
#                self.message=u'插入失败'
#            return self.render()
#
#class SingleArticleEditPage(BasicPage):
#    @AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.form=SingleArticleService.GetForm()
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self):
#        self.form=SingleArticleService.GetForm()
#        if not self.form.validates():
#            self.message=u'输入有误'
#            return self.GET()
#        else:
#            if SingleArticleService.PutByForm(self.form):
#                self.message=u'插入成功'
#            else:
#                self.message=u'插入失败'
#            return self.GET()
#class SingleArticleDeletePage(BasicPage):
#    @AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.form=SingleArticleService.GetForm()
#        return self.render()
#
#

#class NavigationEditPage(NavigationPage):
#    def __init__(self):
#        NavigationPage.__init__(self)
#    @AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        id=int(id)
#        self.form=NavigationService.GetUpdateForm(id)
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self,id):
#        id=int(id)
#        self.form=NavigationService.GetUpdateForm(id)
#        if not self.form.validates():
#            self.message=u'输入有误'
#            return self.render()
#        else:
#            if NavigationService.UpdateByForm(self.form):
#                self.message=u'更新成功'
#            else:
#                self.message=u'更新失败'
#            return self.render()
#class NavigationDeletePage(NavigationPage):
#    def __init__(self):
#        NavigationPage.__init__(self)
#    @AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        id=int(id)
#        self.form=NavigationService.GetForm()
#        if NavigationService.DeleteById(id):
#            self.message=u"删除成功"
#        else:
#            self.message=u"删除失败"
#        return self.render()
#
#class AdministratorPage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='administrator.html'
#        self.message=None
#        self.dashboadSelect['administrator']=True
#    @AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.form=AdministratorService.GetUpdateForm()
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self):
#        self.form=AdministratorService.GetUpdateForm()
#        if not self.form.validates():
#            self.message=u"输入有误"
#            return self.render()
#        else:
#            if AdministratorService.UpdateByForm(self.form):
#                self.message=u"更新成功"
#            else:
#                self.message=u"更新失败"
#            return self.render()
#
#class ArticlePage(BasicPage):
#    """处理 管理文章 页面请求：显示List，显示和处理新增表单"""
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='article.html'
#        self.dashboadSelect['article']=True
#        self.message=None
#        self.actionType="view"
#    #@AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.articleList=ArticleService.GetList()
#        return self.render()
#    
#class ArticleAddPage(ArticlePage):
#    """处理 文章管理 页面中某篇文章的添加：显示和提交表单"""
#    def __init__(self):
#        ArticlePage.__init__(self)
#        self.message=u"添加文章"
#        self.actionType="add"
#    #@AdministratorService.CheckLoginDecorator
#    def GET(self):
#        self.form=ArticleService.GetForm()
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self):
#        self.form=ArticleService.GetForm()
#        if not self.form.validates():
#            self.message=u"输入表单有误"
#            return self.render()
#        else:
#            if ArticleService.PutByForm(self.form):
#                self.message=u"添加文章成功"
#            else:
#                self.message=u"添加文章成功"
#            return self.render()
#
#class ArticleEditPage(ArticlePage):
#    """处理 文章管理 页面中某篇文章的编辑：显示和提交表单"""
#    def __init__(self):
#        ArticlePage.__init__(self)
#        self.message=u"编辑文章"
#        self.actionType="edit"
#    #@AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        self.form=ArticleService.GetUpdateForm(int(id))
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self,id):
#        self.form=ArticleService.GetUpdateForm(int(id))
#        if not self.form.validates():
#            self.message=u"输入表单有误"
#            return self.render()
#        else:
#            if ArticleService.UpdateByForm(self.form):
#                self.message=u"更新成功"
#            else:
#                self.message=u"更新失败"
#            return self.render()
#
#class ArticleDeletePage(ArticlePage):
#    """处理 管理文章 页面中某篇特定文章的删除功能"""
#    def __init__(self):
#        ArticlePage.__init__(self)
#        self.message="删除文章"
#        self.actionType="delete"
#    @AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        id=int(id)
#        self.form=None
#        if ArticleService.DeleteById(id):
#            self.message=u"删除成功"
#        else:
#            self.message=u"删除失败"
#        return self.render()
#
#class CategoryPage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='category.html'
#        self.dashboadSelect['category']=True
#        self.categoryList=CategoryService.GetList()
#        self.message=None
#    @AdministratorService.CheckLoginDecorator  
#    def GET(self):
#        self.form=CategoryService.GetForm()
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self):
#        self.form=CategoryService.GetForm()
#        if not self.form.validates():
#            self.message=u"输入表单有误"
#            return self.render()
#        else:
#            if CategoryService.PutByForm(self.form):
#                self.message=u"插入成功"
#            else:
#                self.message=u"插入失败"
#            return self.render()
#
#class CategoryEditPage(CategoryPage):
#    def __init__(self):
#        CategoryPage.__init__(self)
#    @AdministratorService.CheckLoginDecorator  
#    def GET(self,id):
#        id=int(id)
#        self.form=CategoryService.GetUpdateForm(id)
#        return self.render()
#    @AdministratorService.CheckLoginDecorator
#    def POST(self,id):
#        id=int(id)
#        self.form=CategoryService.GetUpdateForm(id)
#        if not self.form.validates():
#            self.message=u"输入表单有误"
#            return self.render()
#        else:
#            if CategoryService.UpdateByForm(self.form):
#                self.message=u"更新成功"
#            else:
#                self.message=u"更新失败"
#            return self.render()
#class CategoryDeletePage(CategoryPage):
#    def __init__(self):
#        CategoryPage.__init__(self)
#    @AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        id=int(id)
#        self.form=None
#        if CategoryService.DeleteById(id):
#            self.message=u"删除成功"
#        else:
#            self.message=u"删除失败"
#        return self.render()
#class ArchivePage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='archive.html'
#        self.message=None
#        self.archiveList=ArchiveService.GetList()
#        self.dashboadSelect['archive']=True
#    @AdministratorService.CheckLoginDecorator
#    def GET(self):
#        return self.render()
#class ArchiveDeletePage(ArchivePage):
#    def __init__(self):
#        ArchivePage.__init__(self)
#    @AdministratorService.CheckLoginDecorator
#    def GET(self,id):
#        id=int(id)
#        if ArchiveService.DeleteById(id):
#            self.message=u"删除成功"
#        else:
#            self.message=u"删除失败"
#        return self.render()
#class BlogerPage(BasicPage):
#    def __init__(self):
#        BasicPage.__init__(self)
#        self.templateFile='bloger.html'
#        self.message=None
#        self.dashboadSelect['bloger']=True
#    def GET(self):
#        self.form=BlogerService.GetUpdateForm()
#        return self.render()
#    def POST(self):
#        self.form=BlogerService.GetUpdateForm()
#        if not self.form.validates():
#            self.message=u"输入表单有误"
#            return self.render()
#        else:
#            if BlogerService.UpdateByForm(self.form):
#                self.message=u"更新成功"
#            else:
#                self.message=u"更新失败"
#            return self.render()
#
